#pragma GCC optimize(2)
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#include <bitset>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=2e5+10;
struct node {
	ll l, r;
	ll a, b;

	bool operator<(const node& other) const {
		if (l != other.l) {
			return l < other.l;
		} else if (a != other.a) {
			return a < other.a;
		} else {
			return b < other.b;
		}
	}
}d[N];
int p[N];
ll dist[N];
ll find(int x)
{
	if(x!=p[x])
	{
		p[x]=find(p[x]);
	}
	return p[x];
}
void solve()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		ll l,r,a,b;
		cin>>l>>r>>a>>b;
		d[i]={l,r,a,b};
		p[i]=i;
	}
	sort(d+1,d+1+n);
	for(int i=1;i<=n;i++)
	{
		dist[i]=d[i].b;
	}
	for(int i=1;i<n;i++)
	{

		if(d[i].b>=d[i+1].l)
        {
		    p[i]=i+1;
		    dist[i]=max(dist[i],dist[i+1]);
		    dist[i+1]=max(dist[i],dist[i+1]);
		    d[i+1].b=max(d[i].b,d[i+1].b);
		}

	}

	for(int i=1;i<=n;i++)
	{
		p[i]=find(i);
		dist[i]=max(dist[p[i]],dist[i]);
	}

	int m;
	cin>>m;
	for(int i=1;i<=m;i++)
	{
		ll x=0;
		cin>>x;
		int l=1;
		int r=n;
		while(l<r)
		{
			int mid=l+r+1>>1;
			if(d[mid].l<=x) l=mid;
			else r=mid-1;
		}
		if(d[l].l<=x) cout<<max(dist[l],x)<<' ';
		else cout<<x<<' ';
	}
//	for(int i=1;i<=n;i++) dist[i]=0;
	cout<<endl;
}
int main()
{
	IOS;
	int __t=1;
	cin>>__t;

	while(__t--)
	{
		solve();
	}

	return 0;
}

